from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import render
from .models import TopAppTopInfo
from .models import SearchAppCinemaInfo
from cinema_app import models as cinme_model
from movie_app import models as mov_model
# Create your views here.
def index(request):
    keyword = request.GET.get('keyword', None)

    if not keyword:
        error_msg = "请输入关键字"
        return render(request, 'search_page.html', locals())
    a = '"'+keyword+'"'
    movieequalresult = mov_model.Movie_info.objects.filter(Q(name=keyword))

    movielikeresult = mov_model.Movie_info.objects.filter(Q(name__icontains=keyword)
                                                   & ~Q(name=keyword))
    cinemaresult = cinme_model.cinema.objects.filter(Q(name__icontains=keyword))
    b = len(movieequalresult) + len(movielikeresult) +len(cinemaresult)
    for item in cinemaresult:
        item.photodir = item.photodir[1:]
    for item in movieequalresult:
        item.mainact = item.mainact[1:]
        item.show_time = item.show_time.strftime('%Y-%m-%d')
    for item in movielikeresult:
        item.mainact = item.mainact[1:]
        item.show_time = item.show_time.strftime('%Y-%m-%d')
    return render(request, 'search_page.html', locals(),)












